package com.cgy.utils.jmx.jvm.gc;

import com.cgy.utils.jmx.IJvmInfoFactory;
import com.cgy.utils.jmx.jvm.constant.Jvm;
import com.cgy.utils.jmx.jvm.constant.JvmInfo;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;
import java.util.Map;

/**
 * @author CHTK
 */
public class GcFactory extends IJvmInfoFactory {

    @Override
    public void status() {
        List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) {
            put("gc.size", garbageCollectorMXBean.getCollectionCount(), "GC 数量");
            put("gc.time", garbageCollectorMXBean.getCollectionTime(), "GC 耗时");
        }
    }
}
